﻿using Sx.Mall.WebContract;
using Sx.Mall.WebContract.Dto;
using Mall.Infrastructure.Container;
using Mall.Infrastructure.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sx.Mall.Web.Controllers
{
    public class ProductManageController : Controller
    {
        private static InterfaceContainer app = AppDomain.CurrentDomain.GetContainer();

        private IProductService service;

        public ProductManageController()
        {
            service = app.GetSerivce<IProductService>();

        }


        /// <summary>
        /// 产品查询
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        public JsonResult ProductList(ProductDto dto,int page,int rows) 
        {
            dto.Page = new Page();
            dto.Page.PageSize = rows;
            dto.Page.CurrentPage = page;
            var result = service.GetList(dto);
            return Json(result);
        }

        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AddProduct(ProductDto dto) 
        {
            var result = service.Add(dto);
            return Json(result);
        }
    }
}
